package com.rjt.spider;

import java.util.HashMap;
import java.util.Map;

import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Request;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.model.HttpRequestBody;
import us.codecraft.webmagic.processor.PageProcessor;
import us.codecraft.webmagic.utils.HttpConstant;

public class PostSpider implements PageProcessor{
	
	private Site site = Site.me().setRetryTimes(3).setSleepTime(100).setTimeOut(100000);

	@Override
	public void process(Page page) {
		// TODO Auto-generated method stub
		page.putField("content", page.getJson());
	}

	@Override
	public Site getSite() {
		// TODO Auto-generated method stub
		return site;
	}
	public static void main(String[] args) {
    	
    	Spider spider = Spider.create(new PostSpider());
    	
    	Request request = new Request("https://x6m5.ams.game.qq.com/ams/ame/amesvr?ameVersion=0.3&sServiceType=poe&iActivityId=175238&sServiceDepartment=group_5&sSDID=05dd525df63f8016681508c38b68d51c&isXhrPost=true");
    	request.setMethod(HttpConstant.Method.POST);
    	Map<String, Object> map=new HashMap<>();
    	map.put("iActivityId", "175238");
    	map.put("iFlowId", "521731");
    	map.put("g_tk", "609477235");
    	request.setRequestBody(HttpRequestBody.form(map, "utf-8"));
    	request.addHeader("Cookie", "pgv_pvid=5466536452; tvfe_boss_uuid=7fa34fa51b060a7e; pgv_pvi=8250872832; RK=qajlbEGFN1; ptcz=c849b9de700e9fcd8ebf90cbfb950da5c15d3a3315eb4dc749e287cde35966a5; o_cookie=664870911; eas_sid=Y1E5A49172b2m0k4l2X9K1K5l6; pac_uid=1_664870911; _ga=GA1.2.2147096614.1542038153; pt2gguin=o0664870911; gid=8536f215-9449-4099-94cf-1dce5c7a8c8f; p_luin=o0664870911; p_lskey=00040000d34ee37b6bc8e29aa97b7955a319f11fcd73836ffe73cea271452bdc7646e709e0deafe8eb25a8e7; ue_ts=1544273535; ue_uk=d4bbf63575c5755f00f96329020788df; ue_uid=90e080d67e6824bc988d0bec196135ef; ue_skey=57d6b3baec69c6bbf836a11e09ccfc75; LW_uid=91b5q4O4s2D7a3g563o8z0K4A6; LW_pid=36e3ca76abb2b2432de1d0e9df58cefe; LW_sid=K1B5m4Z4x8e5T3l9F1G9e9v5M7; ptui_loginuin=664870911; pgv_si=s8054619136; pgv_info=ssid=s6024730320; _qpsvr_localtk=0.898225897985623; ptisp=cm; uin=o0664870911; p_uin=o0664870911; skey=@5VS36bAQ3; pt4_token=0vLjfNnnQLaKNIY4Ts*QDcZf6O63b2bC21VVl2uvgl8_; p_skey=t93lNGnrTgyOM3N3y2xnvn6jO5ECfgHDv1PygyoXc-s_; IED_LOG_INFO2=userUin%3D664870911%26nickName%3D%2525E5%25259D%2525A6%2525E7%252584%2525B6%26userLoginTime%3D1545730265");
    	spider.addRequest(request).thread(1).run();
	}
}
